﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;

namespace DARE.Save.DataStructures
{
    public class CNodeData : ISaveData
    {
        public string Name;
        public EType Type;
        public CEntityData Entity = new CEntityData();

        public Vector3 position;
        public Quaternion orientation;
        public Vector3 scale;
        public BoundingBox aabb;
        public bool isActive;
        public string parentName;


        public void FillDataStructure(object node)
        {
            CNode n = node as CNode;
            if (n == null)
                return;
            Name = n.Name;
            Type = n.Type;
            Entity.FillDataStructure(n.Entity);
            position = n.Position;
            orientation = n.Orientation;
            scale = n.NScale;
            aabb = n.AABB;
            isActive = n.IsActive;
            if (n.Parent != null && n.Parent != n.Render3D.OriginNode && n.Parent.Name != "0")
                parentName = n.Parent.Name;
        }

        public void FillFromDataStructure(out object node, params object[] paramsData)
        {
            node = (paramsData[0] as CRender3D).CreateNode(Name, Type, Entity == null ? false : true);
            CNode n = node as CNode;
            if (n == null)
                return;
            n.SetPosition(position, CNode.ESpace.WORLD);
            n.Orientation = orientation;
            n.NScale = scale;
            n.IsActive = isActive;
            //n.SetParent(parentName); Done outside.
            object e;
            Entity.FillFromDataStructure(out e, n);
            n.Entity = e as CEntity;
            n.AABBFromWorldBoundingBox = aabb;
        }
    }
}
